package com.genreate.constant;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.genreate.util.xinyuan.XinYuanUtil;
import org.springframework.util.Base64Utils;

import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.YearMonth;

/**
 * cmd 命令常量
 *
 * @author LYS
 * @date 2025-03-06
 */
public class CmdCommandConstant {
    public static void main(String[] args) {
        XinYuanUtil.ipPortFind();
        System.out.println();
    }

    public static void nacosKey(){
        // 自定义生成JWT令牌的密钥
        String nacosSecret = "nacos_20250707_shigzh_nacos_token";
        // 输出密钥长度，要求不得低于32字符，否则无法启动节点。
        System.out.println("密钥长度》》》" + nacosSecret.length());
        // 密钥进行Base64编码
        byte[] data = nacosSecret.getBytes(StandardCharsets.UTF_8);
        System.out.println("密钥Base64编码》》》" + Base64Utils.encodeToString(data));
    }

    /**
     * ping ip端口
     *
     * @param ip   ip
     * @param port 港口
     * @return {@link String }
     */
    public static String pingIpPort(String ip, String port) {
        String command = StrUtil.format("cmd.exe\n" +
                "/c\n" +
                "telnet {} {}", ip, port);
        return command;
    }

    /**
     * maven 打包命令
     *
     * @param projectPath 项目路径
     * @return {@link String }
     */
    public static String mavenPackageCommand(String projectPath) {
        String command = StrUtil.format("cmd.exe\n" +
                "/c\n" +
                "cd {} && mvn clean package", projectPath);
        return command;
    }

    /**
     * maven 打指定配置文件包命令
     *
     * @param projectPath 项目路径
     * @param profileName 配置文件名称
     * @return {@link String }
     */
    public static String mavenPackageProfileCommand(String projectPath, String profileName) {
        String command = StrUtil.format("cmd.exe\n" +
                "/c\n" +
                "cd {} && mvn clean package -P{}", projectPath, profileName);
        return command;
    }

    /**
     * git 拉取代码 命令
     *
     * @param projectPath 项目路径
     * @param branchName  分支名称
     * @return {@link String }
     */
    public static String gitPullCommand(String projectPath, String branchName) {
        String command = StrUtil.format("cmd.exe\n" +
                "/c\n" +
                "cd {} && git pull origin {}", projectPath, branchName);
        return command;
    }

    /**
     * git 切换分支 命令
     *
     * @param projectPath 项目路径
     * @param branchName  分支名称
     * @return {@link String }
     */
    public static String gitCheckoutCommand(String projectPath, String branchName) {
        String command = StrUtil.format("cmd.exe\n" +
                "/c\n" +
                "cd {} && git checkout {}", projectPath, branchName);
        return command;
    }
}
